-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Add keypath apply subscript after open bracket #31980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CodeCompletion] Add keypath apply subscript after open bracket #31980
Conversation
@swift-ci Please smoke test |
@swift-ci Please smoke test Windows |
lib/IDE/ExprContextAnalysis.cpp
Outdated
|
||
// Add 'subscript<T>(keyPath: KeyPath<Root, T>) -> T'. | ||
if (name.getBaseName() == DeclBaseName::createSubscript() && | ||
(baseTy->getAnyNominal() || baseTy->is<ArchetypeType>())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I didn't know this works:
func foo(val: (String, Int)) {
_ = val[keyPath: \.0]
}
This limitation is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for meta type types, the only possible keypath is \.self
(e.g. String.self[keyPath: \.self]
) because keypath cannot refer static members. @benlangmuir Do you think limiting this to non-metatype types here makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up with just adding || baseTy->is<TupleType>()
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion. Seems fine to me either way.
rdar://problem/61016147
5fb4f13
to
38d8b13
Compare
@swift-ci Please smoke test |
@swift-ci Please smoke test Linux |
should suggest
keyPath:
argument.Add
(keyPath: KeyPath<BaseType, T>) -> T
type in the callee analysis for subscript expressions.rdar://problem/61016147